import { post, get } from '@/utils/request';
import { Menu} from '@/pages/backhub/common/menu/store/menuTypes';

/**
 * 获取菜单列表
 * @returns 菜单列表
 */
export const getMenuList = async (): Promise<Menu[]> => {
  return get(`/engine/starhub/menu/getList`);
};

/**
 * 获取菜单列表
 * @returns 菜单列表
 */
export const getActiveMenu = async (): Promise<any[]> => {
  return get(`/engine/starhub/menu/getActiveMenu`);
};

/**
 * 获取菜单列表
 * @returns 菜单列表
 */
export const getActiveMenuTree = async (): Promise<any[]> => {
  return get(`/engine/starhub/menu/getActiveMenuTree`);
};

/**
 * 获取菜单
 * @returns 菜单信息
 */
export const getInfo = async (id: string): Promise<Menu[]> => {
  return get(`/engine/starhub/menu/getInfo/${id}`);
};

/**
 * 创建菜单
 * @param data 菜单数据
 * @returns 创建的菜单
 */
export const createMenu = async (data: Partial<Menu>): Promise<Menu> => {
  return post(`/engine/starhub/menu/add`, data);
};

/**
 * 更新菜单
 * @param id 菜单ID
 * @param data 更新的数据
 * @returns 更新后的菜单
 */
export const updateMenu = async (id: string, data: Partial<Menu>): Promise<Menu> => {
  data.id = id ;
  return post(`/engine/starhub/menu/update`, data);
};

/**
 * 删除菜单
 * @param id 菜单ID
 */
export const deleteMenu = async (ids: string): Promise<void> => {
  return post(`/engine/starhub/menu/delete`, { ids });
};
